function getId(val) {
	return document.getElementById(val)
}

//显示的封装函数
function dedao(val, divs) {
	var d = val.parentNode.nextElementSibling
	var di = d.childNodes
	for(var i = 0; i < di.length; i++) {
		if(di[i].id == divs) {
			di[i].style.display = "block"
		}
	}
}
//隐藏的封装函数
function yincang(val, divs) {
	var d = val.parentNode.nextElementSibling
	var di = d.childNodes
	for(var i = 0; i < di.length; i++) {
		if(di[i].id == divs) {
			di[i].style.display = "none"
		}
	}
}

//获得焦点
function tishi(val) {
	if(val==getId("repassw")){
		if(getId("passw").value==""&&getId("repassw").value==""){
			alert("请先输入密码！！！")
			val.blur()
			return;
		}
	}
	dedao(val, "d4")
	yincang(val, "d2")
	yincang(val, "d3")
	yincang(val, "d5")
}
//失去焦点
function shiqu(val) {
	yincang(val, "d4")
	yanzheng(val)
}

function yanzheng(val){
	//用户名验证
	if(val==getId("usern")){
		return usern(val)
	}
	//密码验证
	if(val==getId("passw")){
		return passw(val)
	}
	//重复密码验证
	if(val==getId("repassw")){
		return repassw(val)
	}
	//昵称验证
	if(val==getId("nicheng")){
		return nicheng(val)
	}
	//手机号验证
	if(val==getId("tel")){
		return tel(val)
	}
	//邮箱验证
	if(val==getId("email")){
		return email(val)
	}
}



//密码验证
function passw(val){
	var zengZe = /^[a-zA-Z0-9]\w{7,11}$/;
	if(val.value != "") {
		if(zengZe.test(val.value)) {
			dedao(val, "d3")
			yincang(val, "d2")
			yincang(val, "d4")
			return true;
		} else {
			dedao(val, "d5")
			yincang(val, "d2")
			yincang(val, "d3")
			yincang(val, "d4")
			return false;
		}
	}
}

//重复密码验证
function repassw(val){
	var zengZe = /^[a-zA-Z0-9]\w{7,11}$/;
	if(getId("passw").value != "") {
		if(val.value==getId("passw").value) {
			dedao(val, "d3")
			yincang(val, "d2")
			yincang(val, "d4")
			return true;
		} else {
			dedao(val, "d5")
			yincang(val, "d2")
			yincang(val, "d3")
			yincang(val, "d4")
			return false;
		}
	}
}

//用户名验证
function usern(val) {
	var zengZe = /^[a-zA-Z0-9]\w{3,17}$/;
	if(val.value != "") {
		if(zengZe.test(val.value)) {
			dedao(val, "d3")
			yincang(val, "d2")
			yincang(val, "d4")
			return true;
		} else {
			dedao(val, "d5")
			yincang(val, "d2")
			yincang(val, "d3")
			yincang(val, "d4")
			return false;
		}
	}
}

//昵称验证
function nicheng(val){
	var zengZe = /^[a-zA-Z0-9\w_+-.\u4e00-\u9fa5]{0,9}$/;
	if(val.value != "") {
		if(zengZe.test(val.value)) {
			dedao(val, "d3")
			yincang(val, "d2")
			yincang(val, "d4")
			return true;
		} else {
			dedao(val, "d5")
			yincang(val, "d2")
			yincang(val, "d3")
			yincang(val, "d4")
			return false;
		}
	}
}

//手机号验证
function tel(val) {
	var zengZe = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
	if(val.value != "") {
		if(zengZe.test(val.value)) {
			dedao(val, "d3")
			yincang(val, "d2")
			yincang(val, "d4")
			return true;
		} else {
			dedao(val, "d5")
			yincang(val, "d2")
			yincang(val, "d3")
			yincang(val, "d4")
			return false;
		}
	}
}

//邮箱验证
function email(val) {
	var zengZe = /^([a-zA-Z0-9]+[_|\.])*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\.])*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
	if(val.value != "") {
		if(zengZe.test(val.value)) {
			dedao(val, "d3")
			yincang(val, "d2")
			yincang(val, "d4")
			return true;
		} else {
			dedao(val, "d5")
			yincang(val, "d2")
			yincang(val, "d3")
			yincang(val, "d4")
			return false;
		}
	}
}

//检测是否有空
function jiance() {
	var inp = document.getElementsByTagName("input")
	for(var i = 0; i < inp.length; i++) {
		if(inp[i].value == "") {
			dedao(inp[i], "d2")
		}
	}
	
	var a = yanzheng(getId("usern"))
	var b = yanzheng(getId("passw"))
	var c = yanzheng(getId("repassw"))
	var d = yanzheng(getId("nicheng"))
	var e = yanzheng(getId("tel"))
	var f = yanzheng(getId("email"))
	if(a&&b&&c&&d&&e&&f){
		alert("注册成功！！！！")
	}
	
	
	
}